//import Page from '../../common/page';
// Page({
// });
import Toast from '../../dist/toast/toast';
var openid = wx.getStorageSync("openid");
Page({
    data: {
      text: "This is page data.",
      newcodes:[],
      newcoder:{},
      htnlText:"",
      isCollect:false
    },
    goStar:function(event){
      //var $this = this;
      var _that =this;
      var id = event.currentTarget.dataset.cid;
      console.log(event.currentTarget.dataset.cid);
      wx.request({
        url: 'http://localhost:8303/collect?id='+id+"&openid="+openid,
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);

          var str = 'newcoder.isCollect'
          if(res.data){
            Toast.success('收藏成功');
            _that.setData({
              isCollect:true
            });
          }else{
            Toast.success('您已取消收藏');
            _that.setData({
              isCollect:false
            });
          }

        }
      })

    },
    onLoad:function(options) {
      console.log(options.id);

      var _that = this;
      debugger
        wx.request({
            url: 'http://localhost:8303/newcoderdetail?id='+options.id+'&openid='+openid,
            header: {
              'content-type': 'application/json' // 默认值
            },
            success (res) {
              console.log(res.data)
              _that.setData({
                newcoder:res.data,
                isCollect:res.data.isCollect
              });
              // var htmltxt = res.data[0].content;
              
              //console.log(_that.data.newcodes)
            }
          })
          
    }
  })
  